#!/bin/bash
ROOT_PATH=/data/project
# 项目名，每个项目需要重新命名
APP_NAME=cdsz-boot
#检查程序是否在运行
is_exist(){
  pid=`ps -ef|grep $APP_NAME.jar|grep -v grep|awk '{print $2}' `
  #如果不存在返回1，存在返回0
  if [ -z "${pid}" ]; then
   return 1
  else
    return 0
  fi
}

#启动方法
start(){
  is_exist
  if [ $? -eq "0" ]; then
    echo "${APP_NAME} is already running. pid=${pid} ."
  else
    nohup "$JAVA_HOME"/bin/java -Xms512m -Xmx1024m \
    -XX:+UseSerialGC \
    -XX:MaxHeapFreeRatio=50 \
    -XX:MinHeapFreeRatio=30 \
    -XX:+HeapDumpOnOutOfMemoryError \
    -XX:HeapDumpPath=$ROOT_PATH/$APP_NAME/dump \
    -Dfile.encoding=UTF-8 \
    -Dspring.profiles.active=test \
    -Dserver.port=10001 \
    -jar $ROOT_PATH/$APP_NAME/$APP_NAME.jar > $APP_NAME.log 2>&1 &
    echo "${APP_NAME} start success"
  fi
}

echo "${APP_NAME} is already..."
start